#include "StudentRegister.h"


StudentRegister::StudentRegister(void)
{
}

void StudentRegister::add(Student* s){
	v.push_back(s);
}

const stringstream StudentRegister::list(){
	stringstream ss;
		for (auto it = v.begin(); it != v.end(); it++){
			ss << **it;
	}
	return ss;
}
StudentRegister::~StudentRegister(void)
{
}

	Student* StudentRegister::getStudent(int index){
		return v.at(index);
	}
	void StudentRegister::remove(int index){
		Student* s = v.at(index);
		v.erase(v.begin()+index);
		delete s;

	}
	void StudentRegister::WriteToFile(){
	ofstream fs = ofstream("register.txt");

		for (auto it = v.begin(); it != v.end(); it++){
			fs << **it;
		}

	}
	void StudentRegister::ReadFromFile(){
		ifstream fs = ifstream("register.txt");
		Student *s;
		stringstream ss;
		char str[106];
		fs.getline(str, 106);
		while(fs.good()){
			s = new Student();
			ss.clear();
			ss <<  str << '\n';
			ss >> *s;
			this->add(new Student(*s));
			fs.getline(str, 106);
		}
	}



